<!--
 * @Author: ybf
 * @Date: 2023-02-21 15:31:51
 * @LastEditTime: 2023-12-07 18:37:10
 * @Description: 描述
 * Copyright (c) 2023 by 慧能分享, All Rights Reserved.
-->
<template>
  <div class="crewManage">
    <!-- <nu-col :span="24" style="height:calc(130px - 20px);"> -->
    <!-- <nutbTitle title="机组查询"></nutbTitle> -->
    <NuVerifyForm :model="formData" ref="formData" label-width="100px" class="searchForm" @searchForm="searchForm"
      :buttons="fyButtons">
      <NuformItem label="机组名称" prop="phyunitName" width="300px">
        <nu-input type="text" v-model="formData.phyunitName" size="middle" placeholder="请输入机组名称"></nu-input>
      </NuformItem>

      <div class="btnBox">
        <nu-button type="primary" class="searchButton" @click="searchTable">搜索</nu-button>
        <nu-button class="searchButton" @click="clearParams">清除</nu-button>
        <!-- <nu-button type="primary" class="searchButton" @click="importTable">导入</nu-button> -->
      </div>
    </NuVerifyForm>
    <!-- </nu-col> -->
    <div class="line"></div>
    <div style="height:35px;position: relative;padding: 0 10px;" class="renovateTime">
      <nu-button type="primary" class="searchButton" @click="addTable">新增</nu-button>
      <nu-button class="searchButton" @click="importTable" v-if="isSysEnergyType">导入</nu-button>
      <!-- <nu-button class="searchButton" @click="exportTable">导出</nu-button> -->
    </div>
    <!-- <nu-col :span="24" style="height: calc(100% - 130px - 61px);"> -->
    <!-- <nutbTitle title="机组列表"></nutbTitle> -->
    <NuTableList :showFilter="false" :columns="columns" :dataSource="dataSource" :options="options"
      :operates="operates(this)" :pagination="pagination" @handleSizeChange="handleSizeChange"
      @handleChangePage="handleChangePage">
    </NuTableList>
    <!-- </nu-col> -->
    <nu-dialog :title="dialogTitle" :visible.sync="dialogShow" width="1150px" center :close-on-click-modal="false"
      top="5vh" :modal-append-to-body="false" @close="diaClose">
      <div class="dialogHeaderSearch">
        <NuVerifyForm :model="dialogFormData" ref="dialogFormData" label-width="210px" class="submitForm"
          @submitForm="diaSubmitForm" :buttons="fyButtons">
          <NuformItem label="机组名称：" prop="phyunitName" width="49%" :rules="[{ required: true, message: '机组名称不能为空' }]">
            <nu-input type="text" v-model="dialogFormData.phyunitName" size="middle" :disabled="dialogFormDisabled"
              placeholder="请输入"></nu-input>
          </NuformItem>
          <NuformItem label="额定有功功率(MW)：" prop="ratedPower" width="49%"
            :rules="[{ required: true, message: '额定有功功率不能为空' }]">
            <nu-input type="number" v-model="dialogFormData.ratedPower" size="middle" :disabled="dialogFormDisabled"
              placeholder="请输入" @change="ratedActivePowerChange"></nu-input>
          </NuformItem>
          <NuformItem label="机组类型：" prop="phyunitType" width="49%" :rules="[{ required: true, message: '机组类型不能为空' }]">
            <nu-select class="searchSelect" :filterable="true" :list="unitTypeList" type="text"
              v-model="dialogFormData.phyunitType" autocomplete="off" style="width: calc(100% - 2px);margin-left: 2px;"
              :disabled="dialogFormDisabled" placeholder="请选择" @change="unitTypeChange">
            </nu-select>
          </NuformItem>
          <NuformItem label="标准调节速率(WM/分钟)：" prop="stAdjustRate" width="49%"
            :rules="[{ required: false, message: '标准调节速率' }]">
            <nu-input type="number" v-model="dialogFormData.stAdjustRate" size="middle" :disabled="true"
              placeholder="请输入"></nu-input>
          </NuformItem>
          <NuformItem label="标准agc响应时间(秒)：" prop="stAgcResptime" width="49%"
            :rules="[{ required: false, message: '电度量不能为空' }]">
            <nu-input type="number" v-model="dialogFormData.stAgcResptime" size="middle" :disabled="true"
              placeholder="请输入"></nu-input>
          </NuformItem>
          <NuformItem label="单机容量(MW)：" prop="normalCap" width="49%" :rules="[{ required: true, message: '单机容量不能为空' }]">
            <nu-input type="number" v-model="dialogFormData.normalCap" size="middle" :disabled="dialogFormDisabled"
              placeholder="请输入" @change="singleMachineChange"></nu-input>
          </NuformItem>
          <NuformItem label="机组允许偏差范围：" prop="unitAlDeviateRange" width="49%">
            <div class="textUnit"> <span>±</span> <nu-input type="text" v-model="dialogFormData.unitAlDeviateRange"
                size="middle" :disabled="true" placeholder="请输入"></nu-input><span>%</span></div>
          </NuformItem>
          <NuformItem label="机组铭牌出力上限(MW)：" prop="maxOutputLimit" width="49%"
            :rules="[{ required: true, message: '机组铭牌出力上限不能为空' }]">
            <nu-input type="number" v-model="dialogFormData.maxOutputLimit" size="middle"
              :disabled="dialogFormDisabled"></nu-input>
          </NuformItem>
          <NuformItem label="机组基本调峰能力下限(MW)：" prop="minOutputLimit" width="49%"
            :rules="[{ required: true, message: '机组基本调峰能力下限不能为空' }]">
            <nu-input type="number" v-model="dialogFormData.minOutputLimit" size="middle" :disabled="dialogFormDisabled"
              placeholder="请输入"></nu-input>
          </NuformItem>
          <NuformItem label="调频死区：" prop="deadZone" width="49%">
            <nu-input type="number" v-model="dialogFormData.deadZone" size="middle" :disabled="true"
              placeholder="请输入"></nu-input>
          </NuformItem>
          <NuformItem label="机组关联母线：" prop="relatedBusName" width="49%"
            :rules="[{ required: false, message: '机组关联母线不能为空' }]">
            <nu-select class="searchSelect" :filterable="true" :list="associatedBusList" type="text"
              v-model="dialogFormData.relatedBusName" autocomplete="off" style="width: calc(100% - 2px);margin-left: 2px;"
              :disabled="dialogFormDisabled" placeholder="请选择">
            </nu-select>
          </NuformItem>
          <NuformItem label="机组批复上网电价（元/MWh）：" prop="gridPrice" width="49%"
            :rules="[{ required: true, message: '机组批复上网电价不能为空' }]">
            <nu-input type="number" v-model="dialogFormData.gridPrice" size="middle" :disabled="dialogFormDisabled"
              placeholder="请输入"></nu-input>
          </NuformItem>
          <NuformItem label="机组投运时间：" prop="effectiveDate" width="49%" :rules="[{ required: false, message: '' }]">
            <el-date-picker v-model="dialogFormData.effectiveDate" type="datetime" placeholder="选择机组投运时间"
              value-format="yyyy-MM-dd HH:mm:ss" style="width: calc(100%)" :disabled="dialogFormDisabled">
            </el-date-picker>
          </NuformItem>
          <NuformItem label="机组退役时间：" prop="terminationDate" width="49%" :rules="[{ required: false, message: '' }]">
            <el-date-picker v-model="dialogFormData.terminationDate" type="datetime" placeholder="选择机组退役时间"
              value-format="yyyy-MM-dd HH:mm:ss" style="width: calc(100%)" :disabled="dialogFormDisabled">
            </el-date-picker>
          </NuformItem>
          <NuformItem label="" prop="stationEnable" width="100%">
            <span style="font-size:15px;font-weight: 600">以下参数与考核计算相关，若无准确数据，建议选择默认值</span>
          </NuformItem>
          <NuformItem label="agc调节动作死区：" prop="agcActionDeadZone" width="49%"
            :rules="[{ required: true, message: 'agc调节动作死区不能为空' }]">
            <div class="textUnit">
              <el-radio-group v-model="dialogFormData.agcActionFlag" :disabled="dialogFormDisabled">
                <el-radio-button label="1">按容量比例</el-radio-button>
                <!-- <el-radio-button label="2">按数值</el-radio-button> -->
              </el-radio-group>
              <span>±</span>
              <nu-input type="number" v-model="dialogFormData.agcActionDeadZone" size="middle"
                :disabled="dialogFormDisabled"
                :placeholder="dialogFormData.agcActionFlag == 1 ? '默认0.5' : '默认1'"></nu-input>
              <span>{{ dialogFormData.agcActionFlag == 1 ? '%' : 'WM' }}</span>
            </div>
          </NuformItem>
          <NuformItem label="agc调节目标死区：" prop="agcTargetDeadZone" width="49%"
            :rules="[{ required: true, message: 'agc调节目标死区不能为空' }]">
            <div class="textUnit">
              <el-radio-group v-model="dialogFormData.agcTargetFlag" :disabled="dialogFormDisabled">
                <el-radio-button label="1">按容量比例</el-radio-button>
                <!-- <el-radio-button label="2">按数值</el-radio-button> -->
              </el-radio-group>
              <span>±</span>
              <nu-input type="number" v-model="dialogFormData.agcTargetDeadZone" size="middle"
                :disabled="dialogFormDisabled"
                :placeholder="dialogFormData.agcTargetFlag == 1 ? '默认0.5' : '默认1'"></nu-input>
              <span>{{ dialogFormData.agcTargetFlag == 1 ? '%' : 'WM' }}</span>
            </div>
          </NuformItem>
          <!-- <NuformItem label="启停磨实际消耗时间：" prop="startStopActualTime" width="49%"
            :rules="[{ required: true, message: '启停磨实际消耗时间不能为空' }]">
            <div class="textUnit">
              <nu-input type="number" v-model="dialogFormData.startStopActualTime" size="middle"
                :disabled="dialogFormDisabled" placeholder="默认0"></nu-input><span>分钟</span>
            </div>
          </NuformItem>
          <NuformItem label="启停磨临界点功率：" prop="startStopCrtpointPower" width="49%"
            :rules="[{ required: true, message: '启停磨临界点功率不能为空' }]">
            <div class="textUnit">
              <span>&emsp;</span><nu-input type="number" v-model="dialogFormData.startStopCrtpointPower" size="middle"
                :disabled="dialogFormDisabled" placeholder="默认0"></nu-input><span>MW</span>
            </div>
          </NuformItem> -->
        </NuVerifyForm>
        <nu-button class="dialogSearchButton" type="primary" @click="diaClose">取消</nu-button>
        <nu-button class="dialogSearchButton" type="primary" @click="diaSave" v-if="dialogTitle == '编辑'">确定</nu-button>
        <nu-button class="dialogSearchButton" type="primary" @click="diaSave" v-if="dialogTitle == '新增'">确定</nu-button>
      </div>
    </nu-dialog>
    <nu-dialog :title="upload.title" :visible.sync="upload.open" width="30%" center :close-on-click-modal="false"
      top="5vh" :modal-append-to-body="false">
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
        :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess"
        :auto-upload="false" drag :data="upload.data" name="file" :file-list="upload.fileList">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
          @click="importTemplate">下载模板</el-link> -->
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </nu-dialog>
  </div>
</template>
  
<script>
import nuCol from "@/components/base/col.vue"
import nutbTitle from "@/components/base/tableTitle.vue"
import NuVerifyForm from "@/components/verify-form"
import NuformItem from "@/components/verify-form/form-item.vue"
import nuInput from "@/components/base/input"
import nuSelect from "@/components/base/select"
import nuButton from "@/components/base/button"
import NuTableList from "@/components/tableList/TableFormList"
import nuDialog from "@/components/base/dialog"
import store from "@/store";
const operates = that => [
  {
    label: '查看',
    icon: '',
    width: '50px',
    isShow: row => {
      return true;
    },
    disabled: row => {
      return false;
    },
    method: row => {
      that.openDetail(row);
    },
  },
  // {
  //   isShow: row => {
  //     return false;
  //   },
  // },
  {
    label: '修改',
    icon: '',
    width: '50px',
    isShow: row => {
      return true;
    },
    disabled: row => {
      return false;
    },
    method: row => {
      that.openEdit(row);
    },
  },
  {
    label: '删除',
    icon: '',
    width: '50px',
    isShow: row => {
      return true;
    },
    disabled: row => {
      return false;
    },
    method: row => {
      that.tbRowdetele(row);
    },
  },
];
import { getToken } from "@/utils/auth";
export default {
  name: "crewManage",
  components: { nuCol, nutbTitle, NuVerifyForm, NuformItem, nuInput, nuSelect, nuButton, NuTableList, nuDialog },
  data() {
    return {
      formData: {
        phyunitName: ""
      },
      dialogFormData: {
        phyunitName: '',
        ratedPower: '',
        phyunitType: '',
        stAdjustRate: '',
        stAgcResptime: '',
        normalCap: '',
        unitAlDeviateRange: '',
        maxOutputLimit: '',
        minOutputLimit: '',
        deadZone: '',
        relatedBusName: '',
        agcAdjustDeadZone: '',
        startStopActualTime: '',
        startStopCrtpointPower: '',
        gridPrice: '',
        effectiveDate: '',
        terminationDate: '',
        agcActionDeadZone: '',
        agcActionFlag: '1',
        agcTargetDeadZone: '',
        agcTargetFlag: '1'
      },
      fyButtons: [],
      operates,
      pagination: {
        pageSize: 20,
        total: 0,
        pageNum: 1,
      },
      dialogTitle: '',
      dialogShow: false,
      unitTypeList: [],
      SADR: [],
      DEAD: [],
      AGCRESP: [],
      associatedBusList: [],
      columns: [
        {
          label: '序号',
          prop: 'ranking',
          width: '70px',
          render: (h, params) => {
            return h('span', params.index + 1 + (this.pagination.pageNum - 1) * this.pagination.pageSize);
          },
        },
        {
          label: '机组名称',
          prop: 'phyunitName',
        },
        {
          label: '关联母线',
          prop: 'relatedBusName',
        },
        {
          label: '额定有功功率（MW）',
          prop: 'ratedPower',
        },
        {
          label: '机组类型',
          prop: 'phyunitType',
          render: (h, params) => {
            let name = null
            this.unitTypeList.map((item) => {
              if (item.value == params.row.phyunitType) {
                name = item.label
              }
            })
            return h('span', name);
          },
        },
        {
          label: '标准调节速率(WM/分钟)',
          prop: 'stAdjustRate',
        },
        {
          label: '标准AGC响应时间',
          prop: 'stAgcResptime',
        },
        {
          label: '单机容量(MW)',
          prop: 'normalCap',
        },
        {
          label: '机组允许偏差范围',
          prop: 'unitAlDeviateRange',
        },
        {
          label: '机组铭牌出力上限(MW)',
          prop: 'maxOutputLimit',
        },
        {
          label: '机组基本调峰能力下限(MW)',
          prop: 'minOutputLimit',
        },
        {
          label: '调频死区（hz）',
          prop: 'deadZone',
        }
      ],
      dataSource: [{}],
      options: {
        'default-expand-all': true,
        'element-loading-background': 'rgba(225,239,242)',
        'element-loading-text': '数据正在加载中',
        'row-key': 'pid',
        'header-cell-style': {
          background: 'rgba(105, 159, 209, 0.7)',
          color: '#fff',
          fontWeight: 'bold',
          fontsize: '16px',
        },
        height: 'calc(100vh - 350px)',
        // props: {
        //   fixed: 'right'
        // }
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_SCADA + window.api.importPhyunits,
        // 上传时附带的额外参数
        data: {},
        fileList: []
      },
      // 机组类型数据
      unitTypeObj: {},
      arr: []
    };
  },
  computed: {
    dialogFormDisabled() {
      return this.dialogTitle == '详情'
    },
    isSysEnergyType() {
      // return (store && store.getters.roles.join().indexOf('admin') > -1) || store.getters.sysEnergyType == 'WIND'
      return store && store.getters.sysEnergyType == 'WIND'
    }
  },
  created() {
    this.getUnitType()
  },
  mounted() {
    this.getCrewManageTableData();
    this.getRelatedBusName();
  },
  methods: {
    /**
     * 查询
     */
    searchTable() {
      this.$refs['formData'].searchForm('form');
    },
    /**
     * form组件内置查询事件
     */
    searchForm(val) {
      if (val) {
        this.pagination.currentPage = 1;
        this.pagination.pageNum = 1;
        this.getCrewManageTableData();
      }
    },
    /**
     * 获取机组类型下拉框数据项
     * 获取标准调节速率
     * 获取标准agc响应时间
     * 获取调频死区
     */
    async getUnitType() {
      let postData = {
        dictType: "",
        pageNum: "1",
        pageSize: "9999"
      };
      let a = []
      for (var i = 0; i < 4; i++) {
        switch (i) {
          case 0:
            postData.dictType = "PHY_UNIT_TYPE"
            a = await this.getDataItem(postData)
            a.map((item) => {
              this.unitTypeList.push({ label: item.dictName, value: item.dictEnName })
            })
            break;
          case 1:
            postData.dictType = "PHY_UNIT_TYPE_SADR"
            a = await this.getDataItem(postData)
            a.map((item) => {
              this.SADR.push(item)
            })
            break;
          case 2:
            postData.dictType = "PHY_UNIT_TYPE_DEAD"
            a = await this.getDataItem(postData)
            a.map((item) => {
              this.DEAD.push(item)
            })
            break;
          case 3:
            postData.dictType = "PHY_UNIT_TYPE_AGCRESP"
            a = await this.getDataItem(postData)
            a.map((item) => {
              this.AGCRESP.push(item)
            })
            break;
        }
      }
    },
    async getDataItem(postData) {
      let data = await this.$httpGet(window.api.getOneLevelDicts, postData)
        .then((response) => {
          if (response.code == 200) {
            return response.rows
          }
        })
      return data;
    },
    /**
     * 新增
     */
    addTable() {
      this.dialogTitle = '新增'
      this.dialogShow = true
    },
    /** 下载模板操作 */
    importTemplate() {
      const h = this.$createElement;
      this.$msgbox({
        title: '提示',
        message: h('div', null, [
          // h('p', { width: '500px' }, '1、下载模板前，请确认已维护好通道工况和设备管理信息哦！下载的模板根据已维护的信息动态生成！'),
          h('p', { width: '500px' }, '1、一次性最多导入500条数据，若数据量大，请分多个excel导入。')
        ]),
        showCancelButton: true,
        confirmButtonText: '确定继续下载',
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonText = '执行中...';
            axios
              .get(process.env.VUE_APP_BASE_SCADA + window.api.downLoadMeterImportTemplate, {
                responseType: "blob",
              })
              .then((response) => {
                const url = window.URL.createObjectURL(new Blob([response.data]));
                const link = document.createElement("a");
                let fname = "导入模板.xls";
                link.href = url;
                link.setAttribute("download", fname);
                document.body.appendChild(link);
                link.click();
                done();
                setTimeout(() => {
                  instance.confirmButtonLoading = false;
                }, 300);
              })
              .catch((error) => { });
          } else {
            done();
          }
        }
      }).then(action => {

      });
      // this.getDownload(window.api.exportRealTelemetrys, {
      //   ...this.formData
      // }, `导入模板.xlsx`)
      // this.download('system/user/importTemplate', {
      // }, `user_template_${new Date().getTime()}.xlsx`)

    },
    /**
     * 导入
     */
    importTable() {
      this.upload.title = "导入";
      this.upload.open = true;
      document.getElementsByTagName("body")[0].className = "upload-body";
    },
    /**
     * 导出
     */
    exportTable() {
      let postData = {
        ...this.formData,
        channelGroupId: this.formData.channel
      };
      axios
        .get(process.env.VUE_APP_BASE_SCADA + window.api.downLoadMeterExportFile, {
          responseType: "blob",
          params: postData,
        })
        .then((response) => {
          const url = window.URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement("a");
          let fname = "设备信息表数据.xlsx";
          link.href = url;
          link.setAttribute("download", fname);
          document.body.appendChild(link);
          link.click();
        })
        .catch((error) => {
          console.log("error:" + JSON.stringify(error));
        });
    },
    /**
     * 每页条数变化事件
     */
    handleSizeChange(val) {
      this.pagination.currentPage = 1;
      this.pagination.pageNum = 1;
      this.pagination.pageSize = val;
      this.getCrewManageTableData();
    },
    /**
     * 改变分页触发事件
     */
    handleChangePage(val) {
      this.pagination.currentPage = val;
      this.pagination.pageNum = val;
      this.getCrewManageTableData();
    },
    /**
     * 额定有功功率change
     */
    ratedActivePowerChange(val) {
      this.unitTypeChange(this.dialogFormData.phyunitType)
    },
    /**
     * 机组类型change
     */
    unitTypeChange(val) {
      let a = ['_SADR', '_AGCRESP', '_DEAD']
      this.SADR.map((item1) => {
        a.forEach((item2) => {
          if (item1.dictEnName == (val + item2)) {
            console.log(this.dialogFormData.ratedPower, item1.dictName)
            this.dialogFormData.stAdjustRate = this.dialogFormData.ratedPower * (item1.dictName / 100)
          }
        })
      })
      this.AGCRESP.map((item1) => {
        a.forEach((item2) => {
          if (item1.dictEnName == (val + item2)) {
            this.dialogFormData.stAgcResptime = item1.dictName
          }
        })
      })
      this.DEAD.map((item1) => {
        a.forEach((item2) => {
          if (item1.dictEnName == (val + item2)) {
            this.dialogFormData.deadZone = item1.dictName
          }
        })
      })
    },
    /**
     * 单击容量change
     */
    singleMachineChange(val) {
      if (val > 100) {
        this.dialogFormData.unitAlDeviateRange = '2'
      } else {
        this.dialogFormData.unitAlDeviateRange = '3'
      }
    },
    /**
     * 表格-编辑
     */
    openEdit(row) {
      this.dialogTitle = '编辑'
      this.dialogShow = true
      Object.assign(this.dialogFormData, row)
      // this.unitTypeObj = this.unitTypeList.filter(item => { return item.value == row.unitType })[0]
      // console.log(this.unitTypeObj)
    },
    /**
     * 表格-详情
     */
    openDetail(row) {
      this.dialogTitle = '详情'
      this.dialogShow = true
      Object.assign(this.dialogFormData, row)
    },
    /**
    * 清除数据
    */
    clearParams() {
      this.resetForm('formData')
    },
    /**
     * 重置表单
     */
    resetForm(formName) {
      this.$refs[formName].resetForm('form');
      for (let k in this[formName]) {
        if (Object.prototype.toString.call(this[formName][k]) == "[object String]") {
          this[formName][k] = ''
        } else if (Object.prototype.toString.call(this[formName][k]) == "[object Array]") {
          this[formName][k] = []
        } else if (Object.prototype.toString.call(this[formName][k]) == "[object Number]") {
          this[formName][k] = ''
        }
      }
    },
    /**
   * dialogFormData组件内置提交事件
   */
    diaSubmitForm(val) {
      if (val) {
        if (this.dialogTitle == '编辑') {
          this.editCrewManageTableData()
        } else if (this.dialogTitle == '新增') {
          this.addcrewManageTableData()
        }
      }
    },
    /**
     * 弹窗-保存
     */
    diaSave() {
      this.$refs['dialogFormData'].submitForm('form');
    },
    /**
     * 弹窗-关闭
     */
    diaClose() {
      this.dialogShow = false
      this.resetForm('dialogFormData')
      this.dialogFormData.agcActionFlag = "1"
      this.dialogFormData.agcTargetFlag = "1"
    },
    /**
     * 表格-删除
     */
    tbRowdetele(row) {
      this.$confirm('确定要删除设备名称【' + row.phyunitName + '】吗？若删除当前设备，则该设备关联的所有量测同时删除，此操作请慎重，是否确认删除？', '确认删除', '确认删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.delStationTableData(row)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    /**
     * 获取表格数据
     */
    getCrewManageTableData() {
      let postData = {
        ...this.formData,
        ...this.pagination
      };
      for (let k in postData.query) {
        if (postData.query[k] && Object.prototype.toString.call(postData.query[k]) == '[object String]') {
          postData.query[k] = postData.query[k].toString().trim();
        }
      }
      this.dataSource = [];
      this.$httpGet(window.api.getCrewManageTableData, postData).then(res => {
        if (res.code == 200 && res.rows) {
          this.pagination.total = res.total;
          this.dataSource = res.rows;
        } else {
        }
      }).catch(err => {

      });
    },
    /**
     * 获取机组关联母线
     */
    getRelatedBusName() {
      let postData = {
        busName: '',
        pageNum: '',
        pageSize: ''
      };
      for (let k in postData.query) {
        if (postData.query[k] && Object.prototype.toString.call(postData.query[k]) == '[object String]') {
          postData.query[k] = postData.query[k].toString().trim();
        }
      }
      this.dataSource = [];
      this.$httpGet(window.api.getBusManageTableData, postData).then(res => {
        if (res.code == 200 && res.rows) {
          res.rows.map((item) => {
            this.associatedBusList.push({ label: item.busName, value: item.busName })
          })
        } else {
        }
      })
    },
    /**
     * 编辑接口
     */
    editCrewManageTableData() {
      let postData = {
        ...this.dialogFormData,
      };
      for (let k in postData.query) {
        if (postData.query[k] && Object.prototype.toString.call(postData.query[k]) == '[object String]') {
          postData.query[k] = postData.query[k].toString().trim();
        }
      }
      this.$httpPost(window.api.savePhyunit, postData).then(res => {
        if (res.code == 200) {
          this.$message({
            message: '成功',
            type: 'success'
          })
          this.diaClose()
          this.getCrewManageTableData()
        } else {
        }
      }).catch(err => {

      });
    },
    /**
     * 删除表格数据
     */
    delStationTableData(row) {
      let postData = {
        phyunitId: row.phyunitId
      };
      for (let k in postData.query) {
        if (postData.query[k] && Object.prototype.toString.call(postData.query[k]) == '[object String]') {
          postData.query[k] = postData.query[k].toString().trim();
        }
      }
      this.$httpGet(window.api.deletePhyunit, postData).then(res => {
        if (res.code == 200) {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getCrewManageTableData()
        } else {
        }
      }).catch(err => {

      });
    },
    /**
     * 新增接口
     */
    addcrewManageTableData() {
      let postData = {
        ...this.dialogFormData,
      };
      for (let k in postData.query) {
        if (postData.query[k] && Object.prototype.toString.call(postData.query[k]) == '[object String]') {
          postData.query[k] = postData.query[k].toString().trim();
        }
      }
      this.$httpPost(window.api.savePhyunit, postData).then(res => {
        if (res.code == 200) {
          this.$message({
            message: '成功',
            type: 'success'
          })
          this.diaClose()
          this.getCrewManageTableData()
        } else {
        }
      }).catch(err => {

      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$message({
        message: response.desc,
        type: 'success'
      })
      this.searchTable();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
  
<style scoped lang="scss">
.crewManage {
  height: calc(100vh - 70px);
}

.searchForm {
  // height: calc(100% - 40px);
  display: flex;
  // align-items: center;
  position: relative;
  flex-wrap: wrap;
  padding-right: 160px;
}

.submitForm {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.btnBox {
  display: flex;
  float: right;
  z-index: 10;
  position: absolute;
  // top: 15px;
  right: 10px;
  margin: 10px 0 0 0;
}

.dialogHeaderSearch {
  background-color: var(--model-bgc);
  padding: 10px 20px;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: right;

  .el-form-item {
    margin-bottom: 4px;

    ::v-deep .el-form-item__error {
      padding-top: 0;
    }
  }
}

::v-deep .el-upload {
  width: 100%;

  .el-upload-dragger {
    width: auto;
  }
}

.textUnit {
  display: flex;
  justify-content: space-around;

  span {
    display: inline-block;
    width: 10px;
    margin: 0 5px;
    white-space: nowrap;
  }
}

.el-radio-group {
  display: flex;
}

::v-deep .el-radio-button__orig-radio:disabled:checked+.el-radio-button__inner {
  border: none;
  color: var(--input-disabled-color) !important;
  background-color: var(--input-disabled-bgc) !important;
}

::v-deep .el-input.is-disabled .el-input__inner {
  color: var(--input-disabled-color) !important;
  cursor: not-allowed !important;
  background-color: var(--input-disabled-bgc) !important;
}
</style>
  
  